#include<iostream>
#include<vector>
using namespace std;


bool check(int arr1[], int arr2[])
{
    for (int i = 0;i < 26;i++)
    {
        if (arr1[i] != arr2[i])
            return false;
    }
    return true;
}
vector<int> findAnagrams(string s, string p) {
    vector<int> v;
    int hash1[26] = { 0 }, hash2[26] = { 0 };
    for (char c : p) hash2[c - 'a']++;

    for (int left = 0, right = 0;right < s.size();right++)
    {
        hash1[s[right] - 'a']++;
            if (right - left + 1 > p.size())
            {
                hash1[s[left] - 'a']--;
                left++;
            }
            if (check(hash1, hash2))
                v.push_back(left);
        }
        return v;
    }


int main()
{
    char s[] = "cbaebabacd", p[] = "abc";
    vector<int>  ret = findAnagrams(s, p);
    for (auto a : ret)
    {
        cout << a <<endl;
    }

    return 0;
}
